#pragma once

#include "D3D9Engine.h"
#include "SceneGraph.h"
#include "timer.h"


class CGameClass
{
	private:
		bool			_isRunning;
		float			_lastFrameTime;
		float			_currentFrameTime;
		CTimer*			_timer;


	protected:
		CD3D9Engine*	_ptrEngine;
		CInputHID*		_ptrInput;
		CSceneGraph*	_sceneGraph;


	public:
		CGameClass(CD3D9Engine*);
		virtual ~CGameClass();


		CSceneGraph*	GetScene() const { return _sceneGraph; }
		CD3D9Engine*	GetEngine() const { return _ptrEngine; }
		CInputHID*		GetInput() const { return _ptrInput; }


		virtual bool InitGameStates() = 0;
		virtual bool CleanupGame() = 0;

		virtual bool UpdateGameGraphics() = 0;
		virtual bool UpdateGameInput(float dt) = 0;
		virtual bool UpdateGameLogic(float dt) = 0;

		bool UpdateInput()
		{
			return this->UpdateGameInput(this->_currentFrameTime);
		}


		bool UpdateLogic()
		{
			return this->UpdateGameLogic(this->_currentFrameTime);
		}


		bool UpdateGraphics()
		{
			return this->UpdateGameGraphics();
		}


		void BeginFrame() 
		{
			_lastFrameTime = _timer->GetTime();
		}


		void EndFrame() 
		{
			float t = _timer->GetTime();
			_currentFrameTime = (t - _lastFrameTime);
		}


		float GetFrameTime() const { return _currentFrameTime; }


		bool IsRunning() const { return _isRunning; }
		void StopGameRunning() { _isRunning = false; }
		void PauseGameRunning(bool pause) { }


		CResourceSprite* NewGameSprite(char* filename, int width, int height, unsigned long colorMask = XRGB(255,255,255));
		CResourceText*	NewTextLable(char* fileType, int size, bool bold, bool italic, bool under);

		int WindowWidth;
		int WindowHeight;
};